import request from '@/utils/request'
import store from '@/store'
import { isTeacher } from '@/utils/permission'

export function pageCourse(pageCourseVo, current, limit) {
    if (isTeacher() && !pageCourseVo.classId) {
        pageCourseVo.teacherId = store.getters.teacherId
    }
    return request({
        url: `/course/course/pageCourse/${current}/${limit}`,
        method: 'post',
        data: pageCourseVo
    })
}

export function deleteCourseByIds(ids) {
    return request({
        url: `/course/course/deleteCourseByIds`,
        method: 'post',
        data: ids
    })
}

export function updateCourse(course) {
    return request({
        url: `/course/course/updateCourse`,
        method: 'post',
        data: course
    })
}

export function getCourseById(id, isContainChapter, isContainComment) {
    return request({
        url: `/course/course/getCourseById/${id}`,
        method: 'get',
        params: {
            isContainChapter,
            isContainComment
        }
    })
}

export function saveOrUpdateCourse(course) {
    return request({
        url: `/course/course/saveOrUpdateCourse`,
        method: 'post',
        data: course
    })
}